package spynx.net.custom;

import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import spynx.net.core.UrlCacheResolver;

public class BugzillaUrlCacheResolver extends UrlCacheResolver {
	
	public static Pattern BUGZILLA = Pattern.compile("show_bug.cgi\\?id=(\\d+)"); 
	
	public static final BugzillaUrlCacheResolver INSTANCE = new BugzillaUrlCacheResolver();
	
	@Override
	public String resolveCacheName(URL query) {
		String name = null;
		String raw = query.toString();
		Matcher matcher = BUGZILLA.matcher(raw);
		if (matcher.find()) { 
			name = matcher.group(1) + (raw.indexOf("xml") > 0? ".xml" : ".html");
			return name;
		}
		return null;
	}
}
